#ifndef YUVVIEWER_H
#define YUVVIEWER_H

#include <QOpenGLWidget>
#include <QOpenGLFunctions_3_3_Core>
#include <QOpenGLShaderProgram>
#include <QOpenGLTexture>
#include <QImage>
#include <QFileDialog>
#include <QMessageBox>
#include <QMouseEvent>
#include <QWheelEvent>

class YUVViewer : public QOpenGLWidget, protected QOpenGLFunctions_3_3_Core
{
    Q_OBJECT

public:
    explicit YUVViewer(QWidget *parent = nullptr);
    ~YUVViewer();

protected:
    void initializeGL() override;
    void resizeGL(int w, int h) override;
    void paintGL() override;

    void mousePressEvent(QMouseEvent *event) override;
    void mouseMoveEvent(QMouseEvent *event) override;
    void wheelEvent(QWheelEvent *event) override;

private slots:
    void openYUVFile();

private:
    void setupVertexData();
    void setupShaders();

    QOpenGLShaderProgram *shaderProgram;
    GLuint VBO, VAO, EBO;

    QOpenGLTexture *textureY;
    QOpenGLTexture *textureU;
    QOpenGLTexture *textureV;

    QByteArray yuvData;
    QPoint lastMousePos;
    float zoomLevel;
    float rotationX, rotationY;

    int imageWidth;
    int imageHeight;
};

#endif // YUVVIEWER_H
